package chuangyi.com.org.ViewModel;

import android.app.Activity;
import android.content.Context;
import android.databinding.Bindable;
import android.os.Bundle;
import android.support.annotation.LayoutRes;
import android.view.MotionEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import java.util.Date;

import chuangyi.com.org.DOMIHome.BR;
import chuangyi.com.org.DOMIHome.Fragments.CommonFragment;
import chuangyi.com.org.DOMIHome.HomeActivity;
import chuangyi.com.org.DOMIHome.R;
import chuangyi.com.org.DOMIHome.Utils.Utils;
import chuangyi.com.org.DOMIHome.Utils.WebApi;
import chuangyi.com.org.DOMIHome.adapter.BindingListItem;
import chuangyi.com.org.DOMIHome.adapter.ListBindingAdapter;

/**
 * Created by zxh on 16/12/9.
 */

public class AdviceListItem extends BindingListItem {
    private String status;
    private boolean expert;
    private int adviceId;
    private int expertId;
    private int uid;
    private String question;
    private Date systime;
    private boolean payflag;
    private String name;
    private int image;
    private boolean allowDelete;

    @Bindable
    public boolean isAllowDelete() {
        return allowDelete;
    }

    public void setAllowDelete(boolean allowDelete) {
        this.allowDelete = allowDelete;
    }

    public boolean isExpert() {
        return expert;
    }

    public void setExpert(boolean expert) {
        this.expert = expert;
    }

    @Bindable
    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
        switch (status) {
            case "未回复":
                image = R.mipmap.waitrep;
                break;
            case "未查看":
                image = R.mipmap.noread;
                break;
            case "已查看":
                image = R.mipmap.read;
                break;
            case "新回复":
                image = R.mipmap.newrep;
                break;
            case "已回复":
                image = R.mipmap.repeat;
                break;
            case "未回答":
                image = R.mipmap.norepeat;
                break;
            case "未支付":
                image = R.mipmap.nopay;
                break;
            case "已支付":
                image = R.mipmap.pay;
                break;
            default:
                image = 0;
                break;
        }
        notifyPropertyChanged(BR.image);
    }

    @Bindable
    public int getImage() {
        return image;
    }

    @Bindable
    public int getAdviceId() {
        return adviceId;
    }

    public void setAdviceId(int adviceId) {
        this.adviceId = adviceId;
    }

    @Bindable
    public int getExpertId() {
        return expertId;
    }

    public void setExpertId(int expertId) {
        this.expertId = expertId;
    }

    @Bindable
    public int getUid() {
        return uid;
    }

    public void setUid(int uid) {
        this.uid = uid;
    }

    @Bindable
    public String getQuestion() {
        return question;
    }

    public void setQuestion(String question) {
        this.question = question;
    }

    @Bindable
    public Date getSystime() {
        return systime;
    }

    public void setSystime(Date systime) {
        this.systime = systime;
    }

    @Bindable
    public boolean isPayflag() {
        return payflag;
    }

    public void setPayflag(boolean payflag) {
        this.payflag = payflag;
    }

    @Bindable
    public String getName() {
        return name;
    }

    public void setName(String expertName) {
        this.name = expertName;
    }

    //    {"consultid":"6","expertid":"","uid":"","question":"","systime":"2016\/12\/03 10:49:48","payflag":"0","expertname":null,"status":"未回复"}
    public AdviceListItem(Context context, @LayoutRes int layoutId) {
        super(context, layoutId);
    }


    /**
     * 点击评价按钮
     *
     * @param view
     */
    public void onClickComment(View view) {
        if (expert) {
            return;
        }
    }

    /**
     * 点击修改按钮
     */
    public void onClickUpdate(View view) {
        if (expert) {
            return;
        }
        AdviceInfo adviceInfo = new AdviceInfo(getContext(), this.name, "", isExpert());
        adviceInfo.setAdviceId(this.adviceId);
        adviceInfo.setAllowSend(true);
        adviceInfo.load();
        AdviceInfo.openAdvice(adviceInfo);
    }

    public void onClickDelete(View view) {
        new Thread(new Runnable() {
            @Override
            public void run() {
                if (WebApi.deleteExpertAsk(getContext(), getAdviceId())) {
                    HomeActivity.notifyListChange(ListBindingAdapter.ACTION_DEL, AdviceListItem.this);
                }
            }
        }).start();
    }

    public void onClickItem(View view) {
        AdviceInfo adviceInfo = new AdviceInfo(getContext(), this.name, "专家", isExpert());
        adviceInfo.setAdviceId(this.adviceId);
        adviceInfo.setExpert(isExpert());
        AdviceInfo.openAdvice(adviceInfo);
    }
}
